package com.yueqian.Service;

import com.yueqian.Dao.DeleteEmployeeDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * 删除员工
 */
@WebServlet(urlPatterns = "/DeleteEmployeeService")
public class DeleteEmployeeService extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = (String) req.getAttribute("number");
        if(id == null){
            req.setAttribute("message","请输入员工编号不能空");
        }
        DeleteEmployeeDao deleteEmployeeDao = new DeleteEmployeeDao();
        Boolean result = deleteEmployeeDao.deleteEmployee(id);
        if(result){
            req.setAttribute("message","删除员工成功");
        }
        else {
            req.setAttribute("message","删除员工失败");
        }
        req.getRequestDispatcher("GetEmployee.jsp").forward(req,resp);
    }
}
